<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>我的房源(房东)</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../../../taofang/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
    <link rel="stylesheet" href="../../../taofang/css/TenantCentre.css">
    <link rel="stylesheet" href="../../../taofang/css/home.css">
</head>
<body>
<script src="../../../taofang/plugins/jquery-3.4.1.js"></script>
<script src="../../../taofang/plugins/bootstrap-3.3.7-dist/js/bootstrap.js"></script>

<%@include file="top.jsp"%>


<div class="col-md-9 zy3">
    <table class="table table-hover">
        <thead>
        <tr>
            <th>房源编号</th>
            <th>代理经纪人</th>
            <th>经纪人电话</th>
            <th>租赁状态</th>
            <th>租赁价格</th>
            <th>取消发布</th>
        </tr>
        </thead>
        <tbody id="tb">
        <c:forEach items="${houseList}" var="h" varStatus="loop">

            <tr>
                <td>${h.id}</td>
                <td>${agentList[loop.count-1].name}</td>
                <td>${agentList[loop.count-1].phone}</td>
                <td name="tdstate">${h.houseState}</td>
                <td>${h.rentMoney}/月</td>
                <td style="color: red">&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" onclick="delhouse(this,${h.id})" class="glyphicon glyphicon-remove-circle"></button></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<%@include file="bottom.jsp"%>


<script>

    $(function () {
        let tdstate = document.getElementsByName("tdstate")
        for (let i = 0; i <tdstate.length ; i++) {
            if (tdstate[i].innerText=="已租出"){
                let tr = tdstate[i].parentElement
                let tddel = $(tr).find('td').eq(5).text("")
            }else{
                tdstate[i].style.color="#cc0000"
                tdstate[i].style.fontWeight="bolder"
            }

        }


    })







    function delhouse(obj,id) {
        if(confirm("确定取消发布")) {
            let tbody = document.getElementById("tb");
            $.ajax({
                type: 'post',
                url: '/taofang/Landlord/delHouse.action',
                data: {'id': id},
                success: function (data) {
                    if (data.code == 200) {
                        let tr = obj.parentElement.parentElement;
                        tbody.removeChild(tr);
                    } else {
                        alert("删除失败!");
                    }
                }
            })
        }else{

        }

    }
</script>

</body>
</html>
